package com.example.statistics.ui.purchase

import android.os.Bundle
import com.example.statistics.R
import com.example.statistics.bean.PurchaseAgentBean
import com.example.statistics.common.BaseLoadingListActivity
import com.example.statistics.ex.format
import com.example.statistics.ex.get
import com.example.statistics.ex.httpGet
import com.example.statistics.net.UrlConfig
import com.example.statistics.utils.Constants
import com.jhj.slimadapter.SlimAdapter
import com.jhj.slimadapter.holder.ViewInjector
import org.jetbrains.anko.startActivity
import java.util.*

class PurchaseAgentEstimateListActivity : BaseLoadingListActivity<PurchaseAgentBean>() {

    var rate = 0.0
    override val title: String
        get() = "采购"
    override val itemLayoutRes: Int
        get() = R.layout.list_item_common_display


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        httpGet<Double>(UrlConfig.PURCHASE_RATE_DATA, config = {
            listParams = listOf("date" to Date().format("yyyy-MM"))
        }, result = {
            rate = it ?: 0.0
        })
    }

    override fun itemViewConvert(adapter: SlimAdapter, injector: ViewInjector, bean: PurchaseAgentBean, position: Int) {
        injector.text(R.id.tv_title, bean.agent)
                .text(R.id.tv_subtitle, bean.advanceInterestRate.toString())
                .clicked {
                    startActivity<PurchaseEstimateListActivity>(Constants.RATE to rate, Constants.DATA to bean)
                }
    }

    override val url: String
        get() = UrlConfig.PURCHASE_AGENT_LIST

}